package vendas.dto;

import gminet.infra.dao.TransferObject;
import gminet.infra.toolkit.NumberToolkit;

import java.util.Date;

import org.primefaces.model.SelectableDataModel;

public class Order extends TransferObject implements SelectableDataModel<Order> {

    private static final long serialVersionUID = -7198579512218107045L;

    private User user;
    private Seller seller;
    private Product product;
    private OrderStatus status;
    private Date orderDate;
    private CurrencyType currencyType;
    private float currencyValue;
    private float buyValue;
    private float shippingValue;
    private float taxValue;
    private Date paymentDate;
    private PaymentStatus paymentStatus;
    private Date arriveDate;
    private Date sellDate;
    private float sellValue;
    private BuyerType buyerType;
    private String buyer;
    private SellStatus sellStatus;
    private String sellerOrderId;
    private String shippingId;
    private String coments;

    public Order() {
        super();
    }

    public User getUser() {
        if (this.user == null) {
            this.user = new User();
        }
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Seller getSeller() {
        if (this.seller == null) {
            this.seller = new Seller();
        }
        return seller;
    }

    public void setSeller(Seller seller) {
        this.seller = seller;
    }

    public Date getOrderDate() {
        return orderDate;
    }

    public void setOrderDate(Date orderDate) {
        this.orderDate = orderDate;
    }

    public String getSellerOrderId() {
        return sellerOrderId;
    }

    public void setSellerOrderId(String idSellerOrder) {
        this.sellerOrderId = idSellerOrder;
    }

    public String getShippingId() {
        return shippingId;
    }

    public void setShippingId(String shippingId) {
        this.shippingId = shippingId;
    }

    public String getComents() {
        return coments;
    }

    public void setComents(String coments) {
        this.coments = coments;
    }

    public CurrencyType getCurrencyType() {
        return currencyType;
    }

    public void setCurrencyType(CurrencyType currencyType) {
        this.currencyType = currencyType;
    }

    public boolean isDollar() {

        return getCurrencyType() != null && getCurrencyType().equals(CurrencyType.DOLLAR);
    }

    public void setDollar(boolean isDollar) {

        setCurrencyType(isDollar ? CurrencyType.DOLLAR : CurrencyType.REAL);
    }

    public float getCurrencyValue() {
        return currencyValue;
    }

    public void setCurrencyValue(float currencyValue) {
        this.currencyValue = currencyValue;
    }

    public Date getPaymentDate() {
        return paymentDate;
    }

    public void setPaymentDate(Date paymentDate) {
        this.paymentDate = paymentDate;
    }

    public PaymentStatus getPaymentStatus() {
        return paymentStatus;
    }

    public void setPaymentStatus(PaymentStatus paymentStatus) {
        this.paymentStatus = paymentStatus;
    }

    public Product getProduct() {
        if (this.product == null) {
            this.product = new Product();
        }
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    public OrderStatus getStatus() {
        return status;
    }

    public void setStatus(OrderStatus status) {
        this.status = status;
    }

    public float getBuyValue() {
        return buyValue;
    }

    public void setBuyValue(float buyValue) {
        this.buyValue = buyValue;
    }

    public float getShippingValue() {
        return shippingValue;
    }

    public void setShippingValue(float shippingValue) {
        this.shippingValue = shippingValue;
    }

    public float getTaxValue() {
        return taxValue;
    }

    public void setTaxValue(float taxValue) {
        this.taxValue = taxValue;
    }

    public Date getArriveDate() {
        return arriveDate;
    }

    public void setArriveDate(Date arriveDate) {
        this.arriveDate = arriveDate;
    }

    public Date getSellDate() {
        return sellDate;
    }

    public void setSellDate(Date sellDate) {
        this.sellDate = sellDate;
    }

    public float getSellValue() {
        return sellValue;
    }

    public String getStringSellValue() {

        return NumberToolkit.getStringFromDouble(getSellValue());
    }

    public void setSellValue(float sellValue) {
        this.sellValue = sellValue;
    }

    public float getTotalDollarBuyValue() {

        float totalBuyValue = 0;
        if (isDollar()) {
            totalBuyValue = getBuyValue() + getShippingValue() + getTaxValue();
        }
        return totalBuyValue;
    }

    public float getTotalBuyValue() {

        float totalBuyValue = 0;
        if (isDollar() && getCurrencyValue() > 0) {
            totalBuyValue = (getBuyValue() + getShippingValue() + getTaxValue()) * getCurrencyValue();
        } else {
            totalBuyValue = getBuyValue() + getShippingValue() + getTaxValue();
        }
        return totalBuyValue;
    }

    public String getStringTotalBuyValue() {

        String stringValue = NumberToolkit.getStringFromDouble(getTotalBuyValue());
        return stringValue;
    }

    public float getTotalGainValue() {

        float totalGainValue = 0;
        if ((!isDollar() || (isDollar() && getCurrencyValue() > 0)) && getSellValue() > 0) {
            totalGainValue = getSellValue() - getTotalBuyValue();
        }
        return totalGainValue;
    }

    public String getStringTotalGainValue() {

        return NumberToolkit.getStringFromDouble(getTotalGainValue());
    }

    public BuyerType getBuyerType() {
        if (this.buyerType == null) {
            this.buyerType = BuyerType.UNDEFINED;
        }
        return buyerType;
    }

    public void setBuyerType(BuyerType buyerType) {
        this.buyerType = buyerType;
    }

    public String getBuyer() {
        return buyer;
    }

    public void setBuyer(String buyer) {
        this.buyer = buyer;
    }

    public SellStatus getSellStatus() {
        if (this.sellStatus == null) {
            this.sellStatus = SellStatus.UNDEFINED;
        }
        return sellStatus;
    }

    public void setSellStatus(SellStatus sellStatus) {
        this.sellStatus = sellStatus;
    }

    @Override
    public Order getRowData(String arg0) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Object getRowKey(Order arg0) {
        // TODO Auto-generated method stub
        return null;
    }

}
